def add_str(cls):
    def __init__(self, year, month, date) -> None:
        self._year = year
        self._month = month
        self._date = date
    cls.__init__ = __init__
    return cls

class A():
    print('A')

    @add_str
    class  Date:
        def __eq__(self, other):
            print('__eq__')
            return (self._year == other._year and self._month == other._month and self._date == other._date )
    
    x = Date(2022,2,22)
    y = Date(2022,2,22)

    print(x == y)

class A1():
    print('A1')

    class  Date:
        def __init__(self, year, month, date) -> None:
            print(id(self))
            self._year = year
            self._month = month
            self._date = date

        def __eq__(self, other):
            print('__eq__')
            return (self._year == other._year and self._month == other._month and self._date == other._date )
    
    x = Date(2022,2,22)
    y = Date(2022,2,22)

    id_x = id(x)
    id_y = id(y)

    print(x == y)

    print(id_x,'idx')
    print(id_y,'idy')
    # 先左边的id，后右边的id

class A2():
    print('A2')

    @add_str
    class  Date:
        def __eq__(self, other):
            print('__eq__')
            return (self._year == other._year and self._month == other._month and self._date == other._date )
    
    class NewData(Date):
        def __eq__(self, other):
            print('NewData')
            return super().__eq__(other)
        pass

    x = Date(2022,2,22)
    y = NewData(2022,2,22)

    # 这里是先执行的后面的，而不是先前的
    # 顺序是，先子类后父类，先左后右
    print(x == y)
class B():
    print('B')

    @add_str
    class  Date:
        def __ne__(self, other):
            print('__ne__')
            return (self._year != other._year or self._month != other._month or self._date != other._date )

    x = Date(2022,2,22)
    y = Date(2022,2,22)

    print(x != y)

class C():
    '''
        定义了 等于函数，但是当使用不等于的时候的时候，会取反。 
    '''
    print('C')

    @add_str
    class  Date:
        def __eq__(self, other):
            print('__eq__')
            return (self._year == other._year and self._month == other._month and self._date == other._date )
    

    x = Date(2022,2,22)
    y = Date(2022,2,22)

    print(x != y)

class D():
    '''
        只是定义了ne函数，却没有 使用 == 的时候，调用ne函数的 取反 的效果 
    '''
    print('D')

    @add_str
    class  Date:
        def __ne__(self, other):
            print('__ne__')
            return (self._year != other._year or self._month != other._month or self._date != other._date )

    x = Date(2022,2,22)
    y = Date(2022,2,22)

    print(x == y)

class E():
    print('E')
    
    @add_str
    class  Date:
        def __eq__(self, other):
            print('__eq__')
            return (self._year == other._year and self._month == other._month and self._date == other._date )
    
        def __ne__(self, other):
            print('__ne__')
            return (self._year != other._year or self._month != other._month or self._date != other._date )

    x = Date(2022,2,22)
    y = Date(2022,2,22)

    print(x == y)
    print(x != y)

class F():
    print('F')

    @add_str
    class Date():
        '''
            __gt__ 和 __lt__ 是一对，只要定义其中的任何一个，都是可以相互使用的。 
        '''
        def __gt__(self, other):
            print('__gt__')
            if self._year > other._year:
                return True
            elif self._month > other._month:
                return True
            elif self._date > other._date:
                return True
            return False
        
        def __lt__(self, other):
            print('__lt__')
            if self._year < other._year:
                return True
            elif self._month < other._month:
                return True
            elif self._date < other._date:
                return True
            return False
        pass

    x = Date(2022,2,22)
    y = Date(2022,2,23)

    print(x < y)
    print(y < x)

    print(x > y)
    print(y > x)


class G():
    print('G')

    @add_str
    class Date():
        def __ge__(self, other):
            print('__ge__')
            if self._year > other._year:
                return True
            elif self._month > other._month:
                return True
            elif self._date > other._date:
                return True
            return False
        
        def __le__(self, other):
            print('__le__')
            if self._year < other._year:
                return True
            elif self._month < other._month:
                return True
            elif self._date < other._date:
                return True
            return False
        pass

    x = Date(2022,2,22)
    y = Date(2022,2,23)
    

    print(x <= y)
    print(x >= y)

    # print(x < y or x ==y) # 这个就是错误的


class G():
    print('G')

    class G1():
        print('G1')
        @add_str
        class Date():
            pass
        x = Date(2022,2,22)
        print(hash(x))

    class G2():
        print('G2')
        @add_str
        class Date():
            def __eq__(self, other):
                print('__eq__')
                return (self._year == other._year and self._month == other._month and self._date == other._date )
        x = Date(2022,2,22)

        # print(hash(x)) # 本行发生错误，因为 eq方法将 hash方法 给覆盖了

    class G3():
        print('G3')
        @add_str
        class Date():
            def __eq__(self, other):
                print('__eq__')
                return (self._year == other._year and self._month == other._month and self._date == other._date )

            def __hash__(self) -> int:
                return 2
    
        x = Date(2022,2,22)

        print(hash(x)) 

    class G4():
        print('G4')
        @add_str
        class Date():
            def __eq__(self, other):
                print('__eq__')
                return (self._year == other._year and self._month == other._month and self._date == other._date )

            def __repr__(self):
                return f'{self._year}{self._month}{self._date}'

            def __hash__(self) -> int:
                return hash(id(self.__repr__()))
    
        x = Date(2022,2,22)
        y = Date(2022,2,22)

        income = {}
        income[hash(x)] = 1000
        income[hash(y)] = 1000
        print(hash(x))
        print(hash(y))
        print(income)
class H():
    print('H')
    @add_str
    class Date():
        def __repr__(self):
                return f'{self._year}{self._month}{self._date}'

        def __bool__(self):
            print('__bool__')
            return False

    x = Date(2022, 2, 22)
    if x:
        print('Hello')
